package flc.ast.fragment.house;

import android.graphics.Color;
import android.view.View;

import androidx.fragment.app.Fragment;

import com.stark.calculator.mortgage.BaseMortFragment;
import com.stark.calculator.mortgage.model.LoanModel;

import flc.ast.R;
import flc.ast.databinding.FragmentHouseKind1Binding;
import stark.common.basic.view.InputUnitView;
import stark.common.basic.view.TextSwitch;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link HouseKind1Fragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class HouseKind1Fragment extends BaseMortFragment<FragmentHouseKind1Binding> {


    @Override
    protected InputUnitView getFundAmountView() {
        return mDataBinding.iuHouseKind1Gjjje;
    }

    @Override
    protected InputUnitView getFundInterestView() {
        return mDataBinding.iuHouseKind1Gjjll;
    }

    @Override
    protected InputUnitView getCommercialAmountView() {
        return mDataBinding.iuHouseKind1SyDkje;
    }

    @Override
    protected TextSwitch getInterestMethodView() {
        return mDataBinding.tsSwitch;
    }

    @Override
    protected View getLprBasisContainer() {
        return mDataBinding.llHouseKind1LprView;
    }

    @Override
    protected View getBaseInterestContainer() {
        return mDataBinding.llHouseKind1JzllView;
    }

    @Override
    protected InputUnitView getLprView() {
        return mDataBinding.iuHouseKind1Lpr;
    }

    @Override
    protected TextSwitch getBasisAddSubView() {
        return mDataBinding.tsHouseKind1Switch;
    }

    @Override
    protected InputUnitView getBasisInputView() {
        return mDataBinding.iuHouseKind1Jd;
    }

    @Override
    protected InputUnitView getCommercialInterestView() {
        return mDataBinding.iuHouseKind1SyDkll;
    }

    @Override
    protected InputUnitView getInterestDiscountView() {
        return mDataBinding.iuHouseKind1Syllzk;
    }

    @Override
    protected InputUnitView getYearView() {
        return mDataBinding.iuHouseKind1Dknx;
    }

    @Override
    protected TextSwitch getLoanMethodView() {
        return null;
    }

    @Override
    protected int onCreate() {
        return R.layout.fragment_house_kind1;
    }

    @Override
    protected void initData() {
        mDataBinding.tvStartCal.setOnClickListener(this);
        mDataBinding.tvHouseKind1Lpr.setOnClickListener(this);
        mDataBinding.tvHouseKind1Jzll.setOnClickListener(this);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()){
            case R.id.tvHouseKind1Lpr:
                clearSelection();
                mDataBinding.tvHouseKind1Lpr.setBackgroundResource(R.drawable.house_type);
                mDataBinding.tvHouseKind1Lpr.setTextColor(Color.WHITE);
                mDataBinding.llHouseKind1LprView.setVisibility(View.VISIBLE);
                break;
            case R.id.tvHouseKind1Jzll:
                clearSelection();
                mDataBinding.tvHouseKind1Jzll.setBackgroundResource(R.drawable.house_type);
                mDataBinding.tvHouseKind1Jzll.setTextColor(Color.WHITE);
                mDataBinding.llHouseKind1JzllView.setVisibility(View.VISIBLE);
                break;
            case R.id.tvStartCal:
                calculate();
                break;
        }
    }

    @Override
    protected void goRetActivity(LoanModel loanModel) {
        super.goRetActivity(loanModel);
    }

    private void clearSelection(){
        mDataBinding.tvHouseKind1Jzll.setTextColor(Color.parseColor("#80050505"));
        mDataBinding.tvHouseKind1Jzll.setBackground(null);
        mDataBinding.tvHouseKind1Lpr.setTextColor(Color.parseColor("#80050505"));
        mDataBinding.tvHouseKind1Lpr.setBackground(null);
        mDataBinding.llHouseKind1JzllView.setVisibility(View.GONE);
        mDataBinding.llHouseKind1LprView.setVisibility(View.GONE);
    }

}